package cn.lycode.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.lycode.common.core.controller.BaseController;
import cn.lycode.common.core.domain.AjaxResult;
import cn.lycode.common.core.domain.model.SelectIdsDTO;
import cn.lycode.common.core.page.PageResult;
import cn.lycode.system.domain.dto.syspost.SysPostAddDTO;
import cn.lycode.system.domain.dto.syspost.SysPostListDTO;
import cn.lycode.system.domain.dto.syspost.SysPostUpdateDTO;
import cn.lycode.system.domain.vo.SysPostVO;
import cn.lycode.system.service.SysPostService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 岗位信息表 Controller
 * @since 2024-09-03
 * @author lyCode
 */
@RestController
@RequestMapping("/sys-post")
@RequiredArgsConstructor
public class SysPostController  extends BaseController{

    private final SysPostService sysPostService;

    //列表分页条件查询
    @SaCheckPermission(value = "sys:post:list")
    @GetMapping("/list")
    public AjaxResult<PageResult<SysPostVO>> listPage(SysPostListDTO dto) {
        return AjaxResult.success(sysPostService.listPage(dto));
    }

    //列表分页条件查询
    @SaCheckPermission(value = "sys:post:list")
    @GetMapping("/option")
    public AjaxResult<List<SysPostVO>> option() {
        return AjaxResult.success(sysPostService.listOption());
    }

    //新增
    @SaCheckPermission(value = "sys:post:add")
    @PostMapping("/add")
    public AjaxResult<Object> add(@Valid @RequestBody SysPostAddDTO dto) {
        return toAjax(sysPostService.add(dto));
    }

    //详情
    @SaCheckPermission(value = "sys:post:list")
    @GetMapping("/{id}")
    public AjaxResult<SysPostVO> detail(@PathVariable Long id) {
    return AjaxResult.success(sysPostService.detail(id));
    }

    //修改
    @SaCheckPermission(value = "sys:post:update")
    @PostMapping("/update")
    public AjaxResult<Object> update(@RequestBody SysPostUpdateDTO dto) {
        return toAjax(sysPostService.update(dto));
    }

    //删除
    @SaCheckPermission(value = "sys:post:remove")
    @PostMapping("/remove")
    public AjaxResult<Object> remove(@RequestBody SelectIdsDTO dto) {
        sysPostService.remove(dto);
        return AjaxResult.success();
    }




}